//
//  FHStatusRetweetView.swift
//  WeiBo
//
//  Created by qfh on 16/7/13.
//  Copyright © 2016年 qiufuhe. All rights reserved.
//

import UIKit
import SnapKit

class FHStatusRetweetView: UIView {
    
    var retweetViewBottom: Constraint?
    
    
    var statusViewMoel: FHStatusViewModel? {
    
        didSet {
        
        
            contentLabel.text = statusViewMoel?.retweetContent
            
            retweetViewBottom?.uninstall()

            if let pictures = statusViewMoel?.status?.retweeted_status?.pic_urls where pictures.count > 0  {
                
                self.snp_updateConstraints(closure: { (make) -> Void in
                    
                    self.retweetViewBottom = make.bottom.equalTo(pictureView).offset(HomeCellMargin).constraint

                    
                })
                
                pictureView.pictures = pictures
                
                pictureView.hidden = false
                
                
            } else {
            
            
                self.snp_updateConstraints(closure: { (make) -> Void in
                    
                    self.retweetViewBottom = make.bottom.equalTo(contentLabel).offset(HomeCellMargin).constraint
                    
                    
                })
                
                pictureView.hidden = true
                
            
            }
        
        }
    
    
    }

    // 微博内容
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.grayColor(), size: 14)
    //  微博 图片视图
    private lazy var pictureView: FHStatusPictrueView = FHStatusPictrueView()
    
    
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUpUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   
    
    func setUpUI() {
        
        contentLabel.backgroundColor = UIColor(white: 0.95, alpha: 1)
        
        pictureView.backgroundColor = backgroundColor

    
        addSubview(contentLabel)
        
        addSubview(pictureView)

    
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            
            
            make.top.equalTo(self).offset(HomeCellMargin)
            
            make.leading.equalTo(self).offset(HomeCellMargin)
            
            make.trailing.equalTo(self).offset(-HomeCellMargin)
        
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(contentLabel.snp_bottom).offset(HomeCellMargin)
            
            make.leading.equalTo(contentLabel)
            
        }
        
        
        
        self.snp_makeConstraints { (make) -> Void in
            
            self.retweetViewBottom = make.bottom.equalTo(pictureView).offset(HomeCellMargin).constraint
            
        }
    
    
    }
    
    
    
    

}
